*additional packages needed*
findit ivreg2
ssc install cem

*dont need to run, already saved*
cem loggdp logpop Int, treatment(nondem)

*for replication files-remove when submitting*
keep RAS4 loggdp logpop Ethnic democracy Int LND relconflict  Religion pctforest lmtnest reldemand_vary relmob_vary altRAS4 cem* polity2 pts recency ongoing propensity Meast MX_scaled SCX_scaled NX_scaled RASindex3_scaled Super scaled_RAS4 relconflict2 relconflict_lessz reldemand_vary_lessz relmob_vary_lessz ccode year conflict 

*main models*
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year) orthog(pctforest lmtnest)
outreg2 using "mainmodels.doc", word dec(2)  label slow(200) replace
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (reldemand_vary = pctforest lmtnest), first cluster(year) orthog(pctforest lmtnest)
outreg2 using "mainmodels.doc", word dec(2) append label slow(200)
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relmob_vary = pctforest lmtnest), first cluster(year) orthog(pctforest lmtnest)
outreg2 using "mainmodels.doc", word dec(2) append label slow(200)

ivreg2 altRAS4 loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altRAS4.doc", word dec(2) label slow(200) replace

*robustness checks
*other models*
xtreg RAS4 relconflict loggdp LND logpop Ethnic democracy Int, mle
outreg2 using "othermodels.doc", word dec(2) replace label
heckman RAS4 relconflict loggdp logpop Ethnic LND democracy Int, select(conflict = loggdp logpop Ethnic democracy pctforest) cluster(year)
outreg2 using "othermodels.doc", word dec(2) append label
reg RAS4 relconflict loggdp logpop Ethnic LND democracy Int [iweight = cem_weights]
outreg2 using "othermodels.doc", word dec(2) append label
xtreg RAS4 relconflict loggdp LND logpop Ethnic democracy Int, fe
outreg2 using "othermodels.doc", word dec(2) append label slow(200)
*full IV*
reg relconflict loggdp logpop Ethnic democracy Int LND pctforest lmtnest, cluster(year) 
outreg2 using "ivfull.doc", word dec(2) replace label
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "ivfull.doc", word dec(2) append label
reg relmob_vary loggdp logpop Ethnic democracy Int LND pctforest lmtnest, cluster(year) 
outreg2 using "ivfull.doc", word dec(2) append label
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relmob_vary = pctforest lmtnest), first cluster(year)
outreg2 using "ivfull.doc", word dec(2) append label
reg reldemand_vary loggdp logpop Ethnic democracy Int LND pctforest lmtnest, cluster(year) 
outreg2 using "ivfull.doc", word dec(2) append label
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (reldemand_vary = pctforest lmtnest), first cluster(year)
outreg2 using "ivfull.doc", word dec(2) append label



*alternate matched
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest) if cem_matched == 1, cluster(year)
outreg2 using "altmatched.doc", word dec(2) replace label

*alternate variables
ivreg2 RAS4 loggdp logpop Ethnic polity2 Int LND (relconflict = pctforest lmtnest),  cluster(year)
outreg2 using "altcontrols.doc", word dec(2) replace label
ivreg2 RAS4 loggdp logpop Ethnic pts Int LND (relconflict = pctforest lmtnest),  cluster(year)
outreg2 using "altcontrols.doc", word dec(2) append label
heckman RAS4 relconflict loggdp logpop Ethnic LND democracy Int recency, select(conflict = loggdp logpop Ethnic democracy pctforest) cluster(year)
outreg2 using "altcontrols.doc", word dec(2) append label

ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND Religion (relconflict = pctforest lmtnest),  cluster(year)
outreg2 using "altcontrols2.doc", word dec(2) replace label

ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND ongoing (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altcontrols3.doc", word dec(2) replace label
*propensity model*
*don't need to run, already saved*
logit conflict loggdp logpop Ethnic democracy pctforest, cluster(year)
predict propensity

xtreg RAS4 relconflict loggdp LND logpop Ethnic democracy Int propensity if cem_matched == 1, mle
outreg2 using "propensity.doc", word dec(2) replace label

*Middle East*
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest) if Meast == 0, first cluster(year)
outreg2 using "MiddleEast.doc", word dec(2) replace label

*lags*
xtreg RAS4 loggdp logpop Ethnic democracy Int LND L.RAS4 relconflict, mle
outreg2 using "lags.doc", word dec(2) replace label
xtreg RAS4 L.loggdp L.logpop L.Ethnic L.democracy L.Int L.LND L.relconflict, mle
outreg2 using "lags.doc", word dec(2) append label

*other DVs*
ivreg2 MX_scaled loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altdvs1.doc", word dec(2) replace label
ivreg2 SCX_scaled loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altdvs1.doc", word dec(2) append label
ivreg2 NX_scaled loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altdvs1.doc", word dec(2) append label

ivreg2 RASindex3_scaled loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altdvs2.doc", word dec(2) append label replace 
ivreg2 altRAS4 loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altdvs2.doc", word dec(2) append label
ivreg2 Super loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altdvs2.doc", word dec(2) append label

ivreg2 scaled_RAS42 loggdp logpop Ethnic democracy Int LND (relconflict = pctforest lmtnest), first cluster(year)
outreg2 using "altdvs3.doc", word dec(2) replace label
*other rel conflict*
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relconflict2 = pctforest lmtnest), first cluster(year)
outreg2 using "otherrelconflict.doc", word dec(2) label replace

*alt IVreg*
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relconflict = pctforest ),  first cluster(year)
outreg2 using "altIVreg.doc", word dec(2) label replace
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (reldemand_vary = pctforest ),  first cluster(year)
outreg2 using "altIVreg.doc", word dec(2) label append
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relmob_vary = pctforest ),  first cluster(year)
outreg2 using "altIVreg.doc", word dec(2) label append

*with extra zeroes removed*
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relconflict_lessz = pctforest lmtnest), first cluster(year)
outreg2 using "lesszeroes.doc", word dec(2) label replace
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (relmob_vary_lessz = pctforest lmtnest), first cluster(year)
outreg2 using "lesszeroes.doc", word dec(2) label append
ivreg2 RAS4 loggdp logpop Ethnic democracy Int LND (reldemand_vary_lessz = pctforest lmtnest), first cluster(year)
outreg2 using "lesszeroes.doc", word dec(2) label append



*graphs*


*graphs (load in new data)*

twoway (bar Coefficient Model) (rcap  upperci lowerci Model), ytitle("Increase in Religious Repression (raw score)") title("Religious Conflict") xlabel(1, valuelabel)
coefplot, drop(_cons) xtitle("Effect on Religious Repression") xline(0)




